package com.cheyunkeji.er.adapter.auction;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.adapter.MyBaseAdapter;
import com.cheyunkeji.er.bean.auction.CooperatorBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Michael on 2017/2/16 15:45.
 */

public class CooperatorListAdapter extends MyBaseAdapter {

    private static final String TAG = CooperatorListAdapter.class.getSimpleName() ;

    public CooperatorListAdapter(ArrayList<CooperatorBean> dataList, Context context) {
        super(dataList, context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.er_mine_cooperator_list_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        CooperatorBean itemBean = (CooperatorBean) dataList.get(position);
        holder.tvCooperatorName.setText(itemBean.getTitle());
        holder.tvCarBrand.setText(itemBean.getBrand());
        String region = itemBean.getRegion() ;

        try{
            holder.tvCity.setText(region.substring(region.indexOf(",") + 1,region.indexOf(",",region.indexOf(",") + 1)));
        }
        catch(Exception e){
            e.printStackTrace();
            Log.e(TAG, "getView: 截取城市名失败");
        }

        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.tv_cooperator_name)
        TextView tvCooperatorName;
        @BindView(R.id.tv_car_brand)
        TextView tvCarBrand;
        @BindView(R.id.tv_city)
        TextView tvCity;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
